package com.asia5b.a5mall.order.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import android.text.TextUtils
import android.view.ViewGroup
import androidx.lifecycle.Observer
import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5mall.middleware.base.SimpleFragment
import com.asia5b.a5mall.middleware.logic.viewmodel.order.LogisDFVM
import com.asia5b.a5mall.middleware.model.order.GuoneiBean
import com.asia5b.a5mall.middleware.model.order.LogisItemBean
import com.asia5b.a5mall.middleware.model.order.OrderDetailModel
import com.asia5b.a5mall.order.R
import com.asia5b.a5mall.order.adapter.LogisItemAdapter
import com.asia5b.a5mall.order.databinding.FragmentLogisticBinding
import kotlinx.android.synthetic.main.fragment_logistic.*

class LogisticInformationFragment : SimpleFragment<LogisDFVM, FragmentLogisticBinding>() {
    override val viewModelClazz: Class<LogisDFVM>
        get() = LogisDFVM::class.java

    override fun getDataBinding(container: ViewGroup?): FragmentLogisticBinding {
        return FragmentLogisticBinding.inflate(layoutInflater,container,false)
    }


    override fun initView() {

    }

    override fun initEvent() {

    }

    override fun startObserver() {
        mViewModel.getLogisItemListResultLiveData.observe(this, Observer {
            getLogisItemListResult(it)
        })
        mViewModel.getExpressList2ResultLiveData.observe(this, Observer {
            getExpressList2Result(it)
        })
    }

    override fun lazyFetchData() {
        if (arguments != null && requireArguments().containsKey("data")) {
            val guoneiBean = requireArguments().getSerializable("data") as GuoneiBean
            val orderDetailModel = requireArguments().getSerializable("OrderDetailModel") as OrderDetailModel

            if (TextUtils.isEmpty(guoneiBean.mainordercode)) {//国内物流
                tv_express_company.text = guoneiBean.express_name
                tv_express_no.text = guoneiBean.express_sn

                mViewModel.getLogisItemListByGuonei("${guoneiBean.express_id}", "${guoneiBean.express_sn}",orderDetailModel)
            } else {//国际物流
                tv_express_company.text =ResString.get(R.string.国际物流)
                tv_express_no.text = guoneiBean.mainordercode
                mViewModel.getLogisItemListByGuoji("${guoneiBean.mainordercode}",orderDetailModel)
            }


        }
    }

     fun getLogisItemListResult(data: ArrayList<LogisItemBean>) {
        val adapter = LogisItemAdapter(data)
        val recyclerview = rv_logistic_info
        recyclerview.layoutManager = LinearLayoutManager(mActivity)
        recyclerview.adapter = adapter
    }

     fun getExpressList2Result(guoneiBeanList: ArrayList<GuoneiBean>) {

    }
}